package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class ItemContainer here.
 * 
 * @author (Jan Skrubbeltrang) 
 * @version (a version number or a date)
 */
public class ItemContainer
{
    // instance variables
    private static ItemContainer instance;
    private ArrayList<Item> items;
    /**
     * Constructor for objects of class ItemContainer
     */
    private ItemContainer()
    {
        items = new ArrayList<Item>();
        // initialise instance variables
    }
    
    public static ItemContainer getInstance()
    {
        if(instance == null)
        {
            instance = new ItemContainer();
        }
        return instance;
    }
    
    public void addItem(Item item)
    {
        items.add(item);
    }
    
    public Item getItem(int itemid) throws IllegalArgumentException
    {
        int index = 0;
        boolean found = false;
        while(index < items.size() && !found)
        {
            if(itemid == items.get(index).getId())
            {
                found = true;
            }
            else
            {
                index++;
            }
        }
        if(!found)
        {
            IllegalArgumentException e = new IllegalArgumentException("ItemController: Unable to find itemID");
            throw e;
        }
        else 
        {
            return items.get(index);
        }
    }
}
